<!DOCTYPE html>
<html>

<head>
  <title>Mails - AIL</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">

  <!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/daterangepicker.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/ail-project.css') }}" rel="stylesheet">

  <!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
	<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
	<script src="{{ url_for('static', filename='js/jquery.daterangepicker.min.js') }}"></script>
	<script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/d3/sparklines.js')}}"></script>

</head>
<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'sidebars/sidebar_objects.html' %}

			<div class="col-12 col-lg-10" id="core_content">

                {% with page=dict_page['page'] %}
				    {% include 'mail/block_mails_search.html' %}
                {% endwith %}

                {% if dict_objects %}
                    {% if mode == "domain_search" %}
                        <table id="table_objects" class="table table-striped table-bordered">
                            <thead class="bg-dark text-white">
                            <tr>
                                <th>Email Domain</th>
                                <th>NB Emails</th>
                            </tr>
                            </thead>
                            <tbody style="font-size: 15px;">
                            {% for m_domain in dict_objects %}
                                <tr>
                                    <td>
                                        <a target="_blank" href="{{ url_for('objects_mail.objects_mail_search') }}?mode=domain_users&domain={{ search_result[m_domain]['content'] }}">
                                            {% if 'hl-start' in search_result[m_domain] %}
                                                <span>{{ search_result[m_domain]['content'][:search_result[m_domain]['hl-start']] }}</span><span class="hg-text">{{search_result[m_domain]['content'][search_result[m_domain]['hl-start']:search_result[m_domain]['hl-end']]}}</span>{{ search_result[m_domain]['content'][search_result[m_domain]['hl-end']:] }}
                                            {% else %}
                                                <span>{{ search_result[m_domain]['content'] }}</span>
                                            {% endif %}
                                        </a>
                                    </td>
                                    <td>{{ dict_objects[m_domain]['nb'] }}</td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>

                    {% else %}
                        <table id="table_objects" class="table table-striped table-bordered">
                            <thead class="bg-dark text-white">
                            <tr>
                                <th>Email</th>
                                <th>First Seen</th>
                                <th>Last Seen</th>
                                <th>Total</th>
                            </tr>
                            </thead>
                            <tbody style="font-size: 15px;">
                            {% for obj_id in dict_objects %}
                                <tr>
                                    <td>
                                        <a target="_blank" href="{{ url_for('correlation.show_correlation') }}?type=mail&id={{ obj_id }}">
                                            {% if 'hl-start' in search_result[obj_id] %}
                                                <span>{{ dict_objects[obj_id]['content'][:search_result[obj_id]['hl-start']] }}</span><span class="hg-text">{{dict_objects[obj_id]['content'][search_result[obj_id]['hl-start']:search_result[obj_id]['hl-end']]}}</span>{{ dict_objects[obj_id]['content'][search_result[obj_id]['hl-end']:] }}
                                            {% else %}
                                                <span>{{ dict_objects[obj_id]['content'] }}</span>
                                            {% endif %}
                                        </a>
                                    </td>
                                    <td>{% if dict_objects[obj_id]['first_seen'] %}{{ dict_objects[obj_id]['first_seen'][0:4] }}-{{ dict_objects[obj_id]['first_seen'][4:6] }}-{{ dict_objects[obj_id]['first_seen'][6:8] }}{% endif %}</td>
                                    <td>{% if dict_objects[obj_id]['last_seen'] %}{{ dict_objects[obj_id]['last_seen'][0:4] }}-{{ dict_objects[obj_id]['last_seen'][4:6] }}-{{ dict_objects[obj_id]['last_seen'][6:8] }}{% endif %}</td>
                                    <td>{{ dict_objects[obj_id]['nb_seen'] }}</td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    {% endif %}

                    {% if dict_page %}
                        {% with page=dict_page['page'], nb_page_max=dict_page['nb_pages'],  nb_first_elem=dict_page['nb_first_elem'], nb_last_elem=dict_page['nb_last_elem'], nb_all_elem=dict_page['nb_all_elem'] %}
                            {% if mode == "domain_search" %}
                                {% set target_url=url_for('objects_mail.objects_mail_search') + "?mode=" + mode + "&domain=" + domain %}
                            {% else %}
                                {% set target_url=url_for('objects_mail.objects_mail_search') + "?mode=" + mode %}
                                {% if username %}
                                    {% set target_url=target_url + "&username=" + username %}
                                {% endif %}
                                {% if domain %}
                                    {% set target_url=target_url + "&domain=" + domain %}
                                {% endif %}
                            {% endif %}
                            {% include 'pagination.html' %}
                        {% endwith %}
                    {% endif %}
                {% else %}
                    <h3 class="text-center">No Results Found</h3>
                {% endif %}

            </div>
        </div>
    </div>

<script>
    var chart = {};
    $(document).ready(function(){
        $("#page-search").addClass("active");
        $("#nav_mail").addClass("active");

        $('#table_objects').DataTable({
            "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
            "iDisplayLength": 10,
            "order": [[ 0, "asc" ]]
        });
  });

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}
</script>

</body>
</html>
